package com.huike.clues.controller;

import com.huike.clues.domain.TbCourse;
import com.huike.clues.domain.vo.PageResult;
import com.huike.clues.dto.CoursePageDTO;
import com.huike.clues.service.CourseService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.MPentity.Course;
import com.huike.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/clues/course")
@Api(tags = "课程管理相关接口")
@Slf4j
public class CourseController {

    @Resource
    CourseService courseService;


    /**
     * 新增课程
     *
     * @param tbCourse
     * @return
     */
    @PostMapping
    @ApiOperation("新增课程")
    public AjaxResult save(@RequestBody TbCourse tbCourse) {
        log.info("新增课程:{}", tbCourse);

        courseService.saveCourse(tbCourse);

        return AjaxResult.success();
    }

    /**
     * 查询课程管理列表
     *
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查询课程管理列表接口")
    public TableDataInfo list(CoursePageDTO coursePageDTO) {
        log.info("查询课程管理列表:{}", coursePageDTO);

        TableDataInfo tableDataInfo = courseService.list(coursePageDTO);
        tableDataInfo.setCode(200);
        return tableDataInfo;
    }

    /**
     * 修改课程信息
     *
     * @param tbCourse
     * @return
     */
    @PutMapping
    @ApiOperation("修改课程信息")
    public AjaxResult update(@RequestBody TbCourse tbCourse) {
        log.info("修改课程信息:{}", tbCourse);
        courseService.update(tbCourse);
        return AjaxResult.success();
    }

    /**
     * 课程下拉列表
     *
     * @param subject
     * @return
     */
    @GetMapping("/listselect")
    @ApiOperation("课程下拉列表")
    public AjaxResult<List<Course>> listSelect(String subject) {
        log.info("课程下拉列表:{}", subject);
        List<Course> courseList = courseService.listSelect(subject);
        return AjaxResult.success(courseList);
    }

    /**
     * 获取课程管理详细信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("获取课程管理详细信息")
    public AjaxResult<Course> getById(@PathVariable Integer id) {
        log.info("获取课程管理详细信息:{}", id);

        Course course = courseService.getById(id);

        return AjaxResult.success(course);
    }

    /**
     * 批量删除课程
     *
     * @return
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("批量删除课程")
    public AjaxResult deleted(@PathVariable int[] ids) {
        log.info("根据Id批量删除课程:{}", ids);
        courseService.deleted(ids);
        return AjaxResult.success();
    }

}
